/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package argtrust.logic;

import java.io.PrintStream;
import aima.core.logic.fol.parsing.ast.Sentence;

import argtrust.util.MyListIterator;

/**
 * An inference node with fact attach.
 * @author Yuqing Tang
 */
public class FactInferenceNode extends InferenceNode {

    private MyListIterator<Sentence> factIter;
    private Sentence factInstance;

    @Override
    public String toString() {
        return factInstance.toString();
    }
    private int hashCode = 0;

    @Override
    public int hashCode() {
        if (0 == hashCode) {
//            hashCode = 17;
            hashCode = super.hashCode();
            if (factIter != null) {
                hashCode = 37 * hashCode + factIter.hashCode();
            }
            if (factInstance != null) {

                hashCode = 37 * hashCode + factInstance.hashCode();

            }
        }
        return hashCode;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }


        final FactInferenceNode rhs = (FactInferenceNode) obj;
        boolean res = super.equals(obj);
        if (factIter != null) {
            res = res && factIter.equals(rhs.factIter);
        } else {
            res = res && rhs.factIter == null;
        }
        if (factInstance != null) {
            res = res && factInstance.equals(rhs.factInstance);
        } else {
            res = res && rhs.factInstance == null;
        }

        return res;

    }

    public FactInferenceNode() {
    }

    public FactInferenceNode(FactInferenceNode orig) {
        super(orig);
        factIter = new MyListIterator<Sentence>(orig.factIter);
        factInstance = orig.factInstance;
    }

    public void setFactInstance(Sentence fact_inst) {
        factInstance = fact_inst;
    }

    public Sentence getFactInstance() {
        return factInstance;
    }

    public void setFactIterator(MyListIterator<Sentence> fact_iter) {
        factIter = fact_iter;
    }

    public MyListIterator<Sentence> getFactIterator() {
        return factIter;
    }

    /**
     * @Override InferenceNode::debug_print.
     * @param out
     */
    public void debug_print(PrintStream out) {
//        out.println("in FactInferenceNode::debug_print");
        out.println(factInstance.toString());
    }
}
